﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4DJackPot
{
    public partial class Results : Dock
    {
        public Results()
        {
            InitializeComponent();
        }

        private void Results_Load(object sender, EventArgs e)
        {
            try
            {
                string currentDate = DateTime.Now.ToString("yyyy-MM-dd");

                string selectQueryString =
                    @"SELECT DISTINCT DRAW_DATETIME FROM GAMES 
                     WHERE DRAW_DATETIME <= '" + currentDate + "' ORDER BY DRAW_DATETIME DESC ";

                DbConn DbConn = new DbConn();
                DataSet resultReadDataSet = DbConn.ReadQuery(selectQueryString);

                foreach (DataRow row in resultReadDataSet.Tables[0].Rows)
                {
                    cB_date.Items.Add(row["DRAW_DATETIME"].ToString());
                }
                
                if(cB_date.Items.Count > 0)
                {
                    cB_date.SelectedIndex = 0;
                }

            }
            catch (Exception e1)
            {
                FileLog FileLog = new FileLog();
                FileLog.WriteErrorLog(e1.StackTrace + "\n" + e1.Message);
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if(checkBox1.Checked)
            {
                ResultBoxForm resultBoxForm = new ResultBoxForm("1", cB_date.SelectedItem.ToString());
                resultBoxForm.Dock = DockStyle.Left;
                this.pN_result.Controls.Add(resultBoxForm);
            }
            else
            {
                foreach (Control childCtl in this.pN_result.Controls)
                {
                    if(((_4DJackPot.ResultBoxForm)(childCtl)).company.companyIdString == "1")
                    {
                        this.pN_result.Controls.Remove(childCtl);
                    }
                }
                
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                ResultBoxForm resultBoxForm = new ResultBoxForm("2", cB_date.SelectedItem.ToString());
                resultBoxForm.Dock = DockStyle.Left;
                this.pN_result.Controls.Add(resultBoxForm);
            }
            else
            {
                foreach (Control childCtl in this.pN_result.Controls)
                {
                    if (((_4DJackPot.ResultBoxForm)(childCtl)).company.companyIdString == "2")
                    {
                        this.pN_result.Controls.Remove(childCtl);
                    }
                }

            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                ResultBoxForm resultBoxForm = new ResultBoxForm("3", cB_date.SelectedItem.ToString());
                resultBoxForm.Dock = DockStyle.Left;
                this.pN_result.Controls.Add(resultBoxForm);
            }
            else
            {
                foreach (Control childCtl in this.pN_result.Controls)
                {
                    if (((_4DJackPot.ResultBoxForm)(childCtl)).company.companyIdString == "3")
                    {
                        this.pN_result.Controls.Remove(childCtl);
                    }
                }

            }
        }

        private void cB_date_SelectedIndexChanged(object sender, EventArgs e)
        {
            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
            /*
            foreach (Control childCtl in this.pN_result.Controls)
            {
                this.pN_result.Controls.Remove(childCtl);
            }
             */
        }




    }
}
